package com.practice.misc;

public class PayPal {
	public String convert(String text, int n) {
		if (n == 1) return text;
		
		StringBuilder[] sb = new StringBuilder[n];
		for (int i=0; i<n; i++) sb[i] = new StringBuilder();
		
		int step = 1;
		int index = 0;
		for (int i=0; i<text.length(); i++) {
			sb[index].append(text.charAt(i));
			index += step;
			if (index == -1) {
				index = 1; step = 1;
			}
			else if (index == n) {
				index = n - 2; step = -1;
			}
		}
		
		for (int i=1; i<n; i++) sb[0].append(sb[i]);
		return sb[0].toString();
	}
}
